package cn.edu.ujn.lab3.util;

import java.util.logging.Logger;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;

import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
@Aspect
@Component
public class LogAspect {
	public static Logger log = Logger.getLogger(LogAspect.class.toString());
	// 定义切入点表达式
	@Pointcut("execution(* cn.edu.ujn.lab3.*.*.*(..))")
	private void myPointCut(){}	
	// 环绕通知	
	@Around("myPointCut()")
	public Object myAround(ProceedingJoinPoint proceedingJoinPoint)   throws Throwable {
		
		log.info("环绕通知开始：方法开始执行......"+ proceedingJoinPoint.getSignature().getName());
		Object obj = proceedingJoinPoint.proceed();
		log.info("环绕通知结束：方法执行结束......"+ proceedingJoinPoint.getSignature().getName());
		return obj;
	}
	// 异常通知
	@AfterThrowing(value="myPointCut()",throwing="e")
	public void myAfterThrowing(JoinPoint joinPoint, Throwable e) {
		log.info("异常通知：" + "出错了" + e.getMessage());
	}
}